class Container {
    static of (value) {
        return new Container(value);
    }
    constructor (value) {
        this._value = value;
    }
    map(fn) {
        return Container.of(fn(this._value));
    }
}

class MayBe {
    static of(value) {
        return new MayBe(value);
    }

    constructor(value) {
        this._value = value;
    }

    map(fn) {
        // return MayBe.of(fn(this._value));
        return this.isNothing() ? this : MayBe.of(fn(this._value));
    }
    
    isNothing() {
        return this._value === null || this._value === undefined;
    }
}


const fp = require('lodash/fp');

const maybe = MayBe.of([5, 6, 1]);

const ex1 = function(value) {
    const result = fp.map(function(item) {
        return fp.add(item, 1);
    }, value);
    return result;
};

console.log('ex1', maybe.map(ex1));